<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<script type="text/javascript" src="<%=basePath %>js/jquery.js"></script>
<script type="text/javascript" src="<%=basePath %>js/jquery.json-2.4.min.js"></script>
<%--<link rel="stylesheet" type="text/css" href="<%=basePath %>css/regist_style.css"/>--%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<base href="<%=basePath%>">
<title>考试系统</title>
<style type="text/css">
   

</style>


	<script type="text/javascript">
	var index = 1;
	var pageCount = 0;
	function bind(index){
		var tindex = index;
		var sel = $("#selectOne").val();
		var toe = $("#teacherOrexam").val();
		var sta = $("#status").val();
		var coj = $("#isjava").val();
		$.getJSON("<%=request.getContextPath()%>/PaperAction/PaperAction!getPapers.action?",{selectOne:sel,teacherOrexam:toe,status:sta,isjava:coj,index:tindex},  backcall);
	}
	
	$(function (){
		$("#template").hide();   //隐藏模板
		ChangeState(0,1);//设置翻页按钮的初始状态
		bind(1);
	})
	
	function backcall(data){

		$("[@id=ready]").remove();
		$.each(data.list, function(index, datas){

			var row = $("#template").clone();
			row.find("#pid").text(datas.id);
			row.find("#pname").text(datas.papername);
			if(datas.isjava==1){
				row.find("#type").text("C");
			}
			else{
				row.find("#type").text("JAVA");
			}
			
			row.find("#status").text(datas.status);     //考试状态
			row.find("#tname").text(datas.teachername);      //老师名称
			var begintime =datas.begintime;
			var endtime =datas.endtime;
			if(begintime != null && endtime !=null ){
				begintime= begintime.replace(/T/gm,' ');
				endtime= endtime.replace(/T/gm,' ');
			}
			row.find("#btime").text(begintime);       //考试开始时间
			row.find("#etime").text(endtime);     //考试结束时间
			
			if(<s:property value="#session.role" />==0){	
<%--				begintime = new Date(begintime.replace(/-/ig,'/'));--%>
<%--	        	endtime = new Date(endtime.replace(/-/ig,'/'));--%>
				if(datas.status == "running"){
					var method = "参加";
		            var canshu = "<a href='/acmctgu/Exam/ExamAction!beginExam.action?id="+datas.id+"&type="+datas.isjava+"'>"+method+"</a>";
				}						
	            row.find("#method").html(canshu);
			}
			else if(<s:property value="#session.role" />==1){									
	            var method = "限制";
	            var canshu = "<div href='/acmctgu/Teacher/TeacherAction!paperInfo.action?paperId="+datas.id+"'>"+method+"</div>";
				row.find("#method").html(canshu);
				}
			
			else if(<s:property value="#session.role" />==2){
				var method = "详细";
				var canshu = "<a href='/acmctgu/Teacher/TeacherAction!paperInfo.action?paperId="+datas.id+"'>"+method+"</a>";
	 			row.find("#method").html(canshu);
				
			}
			
			row.appendTo("#datatable");    
			row.attr("id","ready");
		})
		$("[@id=ready]").show();
		$("#index").text(data.currentpage);                //显示当前第几页
		$("#totalpage").text(data.totalpagecount);		   //显示一共多少页
		index = data.currentpage
		pageCount =data.totalpagecount
	}
	
	function del(id){
		//window.location.href="<%=request.getContextPath() %>/Paper/PaperAction!paperDel.action?id=${paper.id}";
		//$.get("<%=request.getContextPath() %>/Paper/PaperAction!paperDel.action?id=${paper.id}",null,delback);
	}
	
	function delback(data){
		ChangeState(0,1);//设置翻页按钮的初始状态
		bind(1);
	}
	
	function first(){
		index = 1;
        ChangeState(0,1);
        bind(index); 
	}
	
	function last(){
		index = pageCount;
        ChangeState(1,0);
        bind(index);  
	}
	
	function previous(){
		index -= 1;
        ChangeState(-1,1);           
        if(index <= 1)
        {
        	index = 1;
            ChangeState(0,-1);
        }
        bind(index); 
	}
	
	function next(){
		index += 1;
        ChangeState(1,-1);
        if(index>=pageCount)
        {
        	index = pageCount;
            ChangeState(-1,0);
        }
        bind(index); 
	}
	
	function gotoPage(){
		index = $("#goindex").val();
		if(index<1 || index>pageCount)
			{
				alert("输入的页码错误，请正确输入");
				return false;
			}
		else if(index==pageCount)
			{
				ChangeState(1,0);
			}
		else if (index==1){
			ChangeState(0,1);
		}
			bind(index);
	}

	
	function ChangeState(state1,state2)                    //设置翻页按钮状态
    {
        if(state1 == 1)
        {           
            document.getElementById("first").disabled = "";
            document.getElementById("previous").disabled = "";
        }
        else if(state1 == 0)
        {           
            document.getElementById("first").disabled = "disabled";
            document.getElementById("previous").disabled = "disabled";
        }
        if(state2 == 1)
        {
            document.getElementById("next").disabled = "";
            document.getElementById("last").disabled = "";
        }
        else if(state2 == 0)
        {
            document.getElementById("next").disabled = "disabled";
            document.getElementById("last").disabled = "disabled";
        }
    }
	
	
	
	
	</script>
</head>
<body style="overflow-x: hidden;overflow-y: auto">

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="24" bgcolor="#353c44"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%" height="19" valign="bottom"><div align="center"><img src="images/tb.gif" width="14" height="14" /></div></td>
                <td width="94%" valign="bottom"><span class="STYLE"> 考试基本信息列表</span></td>
              </tr>
            </table></td>
            <td><div align="right"></div></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  

  <div id="c">
  	<label>试卷名称或老师名称 </label><input type="text" name="paper.selectOne" id ="selectOne" />
  	<label>选择条件 </label>
  	<select name='paper.teacherOrexam' id="teacherOrexam">
                	<option value=""></option>
                    <option  value='teacher'>teacher</option>
                    <option  value='exam'>exam</option>
                </select> 
  	<label>考试状态 </label>
  	<select name='paper.status' id="status" >
                	<option value=""></option>
                    <option  value='all'>all</option>
                    <option  value='running'>running</option>
                    <option  value='pass'>pass</option>
                    <option  value='forever'>forever</option>
                    <option  value='waiting'>waiting</option>
                </select> 
  	<label>试卷类型 </label>
  	<select name='paper.isjava' id="isjava" >
                	<option value=""></option>
                    <option  value='java'>java</option>
                    <option  value='c'>c</option>
    </select> 
    
    <input type="button" value="查询" onclick = "bind(1)"/>
    
  	</div>
  	
  	
  <tr>
    <td ><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce" id = "datatable">
      <tr >
        <td width="5%" height="20" bgcolor="d3eaef" class="style"><div align="center"><span class="style">考试编号</span></div></td>
        <td width="15%" height="20" bgcolor="d3eaef" class="style"><div align="center"><span class="style">考试名称</span></div></td>
        <td width="5%" height="20" bgcolor="d3eaef" class="style"><div align="center"><span class="style">考试类型</span></div></td>
        <td width="14%" height="20" bgcolor="d3eaef" class="style"><div align="center"><span class="style">开始时间</span></div></td>
        <td width="14%" height="20" bgcolor="d3eaef" class="style"><div align="center"><span class="style">结束时间</span></div></td>
        <td width="5%" height="20" bgcolor="d3eaef" class="style"><div align="center"><span class="style">考试状态</span></div></td>
        <td width="5%" height="20" bgcolor="d3eaef" class="style"><div align="center"><span class="style">创建者</span></div></td>
        <td width="10%" height="20" bgcolor="d3eaef" class="style"><div align="center"><span class="style">基本操作</span></div></td>
        
      </tr>
      
      <tr id ="template">
      	<td height="20" bgcolor="#FFFFFF" class="style"><div align="center"><span id ="pid" class="style"> </span></div></td>
      	<td height="20" bgcolor="#FFFFFF" class="style"><div align="center"><span id="pname" class="style"> </span></div></td>
      	<td height="20" bgcolor="#FFFFFF" class="style"><div align="center"><span id="type" class="style"> </span></div></td>
      	<td height="20" bgcolor="#FFFFFF" class="style"><div align="center"><span id="btime" class="style"> </span></div></td>
      	<td height="20" bgcolor="#FFFFFF" class="style"><div align="center"><span id="etime" class="style"> </span></div></td>
      	<td height="20" bgcolor="#FFFFFF" class="style"><div align="center"><span id="status" class="style"> </span></div></td>
      	<td height="20" bgcolor="#FFFFFF" class="style"><div align="center"><span id="tname" class="style"> </span></div></td>
      	<td height="20" bgcolor="#FFFFFF" class="style"><div align="center"><span id="method" class="style"> </span></div></td>
      </tr>
    </table></td>
  </tr>
  
   
	</table>
	
	<div id ='wait'></div>
	
	
	第<span id ="index"></span>页   &nbsp 共<span id ="totalpage">0</span>页   &nbsp 
	<input type="button" id="first" value="首页" onclick="first()"/>
	<input type="button" id="previous" value="上一页" onclick="previous()"/>
	<input type="button" id="next" value="下一页"/ onclick="next()">
	<input type="button" id="last" value="最后一页" onclick = "last()"/>
	<input type="text" id="goindex"  height: 16px width: 120px/>
	<input type="button" id="gotoPage" value="跳转" onclick="gotoPage()"/>
	

</body>
</html>
